home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (DO) / Nibble Volume 07, No. 06 (1986-06)(MicroSPARC)(Side A).zip / Nibble Volume 07, No. 06 (1986-06)(MicroSPARC)(Side A).do / MICROSCOPE.S < prev    next >
Text File  |  1996-12-24  |  49KB  |  1,343 lines

  1. *
  2. ***************************
  3. *                         *
  4. *       MicroScope        *
  5. *     by Ong Tee Yong     *
  6. * 7628C, Pantai Pringgit, *
  7. *    Melaka, Malaysia     *
  8. *                         *
  9. *   Copyright (C) 1986    *
  10. *   by MicroSPARC, Inc.   *
  11. *   Concord, MA  01742    *
  12. *                         *
  13. ***************************
  14. *        MERLIN ASSEMBLER
  15. *
  16.           ORG $2000
  17. *
  18. TEMP      EQU $19        ;Temporary work location
  19. TEMPA     EQU $1A        ;Temporary work location
  20. PTR       EQU $1B        ;Used in array listing rtn
  21. LISTTEMP  EQU $1D        ;Location used in list rtn
  22. VIDEOTMP  EQU $1E        ;Temporary storage for INVFLG
  23. WNDTMP    EQU $1F        ;Store top line of scroll window
  24. WNDS      EQU $20        ;Left column of scroll window
  25. WNDTOP    EQU $22        ;Top line of scroll window
  26. CH        EQU $24        ;Cursor column
  27. CV        EQU $25        ;Cursor row
  28. INVFLG    EQU $32        ;Flag for nature of screen output
  29.                          ;      Inverse, Flash, Normal
  30. PROMPT    EQU $33        ;Prompt character stored here
  31. A1L       EQU $3C        ;MOVE start
  32. A2L       EQU $3E        ;MOVE end
  33. A4L       EQU $42        ;MOVE destination
  34. LINNUM    EQU $50        ;Location of line no.
  35. VARTBL    EQU $69        ;Start of simple variable pointer
  36. ARYTBL    EQU $6B        ;Pointer to start of array
  37. VAREND    EQU $6B        ;End of simple variable pointer
  38. ARYEND    EQU $6D        ;Pointer to end of array
  39. HIMEM     EQU $73        ;Applesoft Himem
  40. CURLIN    EQU $75        ;Current line no. being executed
  41. OLDLIN    EQU $77        ;Location to save line no. at
  42.                          ;      which program halted
  43. LOWTR     EQU $9B        ;Location used by FINDLIN rtn
  44. FACMO     EQU $A0        ;Mid. order byte of FAC mantissa
  45. FACLO     EQU $A1        ;Low order byte of FAC mantissa
  46. TXTPTR    EQU $B8        ;Text pointer address
  47. STEPFLG   EQU $CE        ;Flag to indicate stepping mode
  48. AUTOFLG   EQU $CF        ;Auto-stepping flag
  49. CHTEMP    EQU $D6        ;Storage for cursor column
  50. CVTEMP    EQU $D7        ;Temporary storage for cursor row
  51. AHOLD     EQU $EB        ;Temporary storage for (A)
  52. XREG      EQU $EC        ;Temporary storage for (X)
  53. YREG      EQU $ED        ;Temporary storage for (Y)
  54. STATUS    EQU $EE        ;Temporary storage for (P)
  55. CONTFLG   EQU $EF        ;Program continuation flag
  56. PRTFLG    EQU $FA        ;Line no. printing flag
  57. NOWLNFLG  EQU $FB        ;Print line just executed flag
  58. LINNOTMP  EQU $FC        ;Storage of current line no.
  59. VRYTBL    EQU $FE        ;Temporary area used in variable
  60.                          ;      and array listing rtn
  61. BUFF      EQU $200       ;Buffer used in array listing rtn
  62. AMPER     EQU $3F5       ;Holds jump instruction for & rtn
  63. KEYBOARD  EQU $C000      ;Keyboard input location
  64. KBDSTRB   EQU $C010      ;Clear keyboard strobe location
  65. PGMSTP    EQU $D43F      ;Program stop rtn
  66. GDBUFS    EQU $D539      ;Zero buff. end, clear high bits
  67. FINDLIN   EQU $D61A      ;Point LOWTR to line in LINNUM
  68. INCPTR    EQU $D72C      ;Rtn used when list line no.
  69. STROUT    EQU $DB3A      ;Print string pointed to by (Y,A)
  70. STRPRT    EQU $DB3D      ;Print string with descriptor
  71.                          ;      pointed to by FACMO-FACLO
  72. OUTDO     EQU $DB5C      ;Applesoft output rtn
  73. FRMNUM    EQU $DD67      ;Evaluate expression
  74. GETADR    EQU $E752      ;Convert FAC to integer in LINNUM
  75. MOVFM     EQU $EAF9      ;Applesoft FP move rtn
  76. LINPRT    EQU $ED20      ;Print current line no
  77. LINPRNT   EQU $ED24      ;Print decimal no. of (A,X)
  78. PRNTFAC   EQU $ED2E      ;Print current value of FAC
  79. SETTXT    EQU $FB39      ;Switch to text screen
  80. SETTXT1   EQU $FB3C      ;Restore normal values of text
  81.                          ;      screen
  82. TABV      EQU $FB5B      ;Position cursor at row in (A)
  83. HOME      EQU $FC58      ;Clear text screen
  84. KYIN      EQU $FD1B      ;Keyboard input rtn
  85. GETLN     EQU $FD6F      ;Get an input line with no prompt
  86. CROUT     EQU $FD8E      ;Print carriage return
  87. COUT      EQU $FDED      ;Print character in (A)
  88. COUT1     EQU $FDF0      ;Output directly to screen
  89. MOVE      EQU $FE2C      ;Move routine
  90. BELL      EQU $FF3A      ;Output bell character via CSWL
  91. *
  92. GETBUFR   EQU $BEF5      ;Allocate buffer space
  93. FREBUFR   EQU $BEF8      ;Free all allocated buffer space
  94. *
  95. ***********************************************************
  96.           JSR SETTXT     ;Print Title and Copyright Notice
  97.           JSR HOME
  98.           LDA #<ASP
  99.           LDX #>ASP
  100.           STA TEMP
  101.           STX TEMP+1
  102.           LDY #$FF
  103. MSG       INY
  104.           LDA (TEMP),Y
  105.           JSR TABV
  106.           INY
  107.           LDA (TEMP),Y
  108.           STA CH
  109. MSG1      INY
  110.           LDA (TEMP),Y
  111.           BEQ MSG
  112.           CMP #$8D
  113.           BEQ STARTUP
  114.           JSR COUT1
  115.           BNE MSG1
  116. *
  117. STARTUP   LDA $BF00      ;ProDOS?
  118.           CMP #$4C
  119.           BNE MOVEUP
  120.           JSR FREBUFR    ;Yes. Free all alloc. buffer
  121.           LDA #14
  122.           JSR GETBUFR    ;Allocate buffer space
  123. MOVEUP    LDX #<START    ;DOS 3.3 and ProDOS. Move stepper
  124.           LDY #>START    ;      program to $8C00
  125.           STX A1L
  126.           STY A1L+1
  127.           LDX #<END
  128.           LDY #>END
  129.           STX A2L
  130.           STY A2L+1
  131.           LDX #<INSTALL
  132.           LDY #>INSTALL
  133.           STX A4L
  134.           STY A4L+1
  135.           LDY #0
  136.           JSR MOVE
  137.           JMP INSTALL    ;Jump to MicroScope program
  138. *
  139. *
  140. ASP       DFB 7,10
  141.           INV "                     "
  142.           DFB 0
  143.           DFB 8,10
  144.           INV "     MICROSCOPE      "
  145.           DFB 0
  146.           DFB 9,10
  147.           INV "                     "
  148.           DFB 0
  149.           DFB 12,19
  150.           ASC "BY"
  151.           DFB 0
  152.           DFB 15,14
  153.           ASC "ONG TEE YONG"
  154.           DFB 0
  155.           DFB 20,0
  156.           ASC "**  COPYRIGHT 1986 MICROSPARC,  INC.  **"
  157.           DFB $8D
  158. START     = *
  159. **********************************************************
  160. *        INSTALLATION OF EXTENSION TO CHRGET RTN         *
  161. **********************************************************
  162. *
  163.           ORG $8C00
  164. *
  165. INSTALL   LDA #$4C       ;Jump instruction
  166.           STA AMPER      ;Modify & rtn to reinitialize pgm
  167.           STA $BA
  168.           LDA #<EXTGET   ;Modify Applesoft Chrget rtn to
  169.           STA $BB        ;      point to stepper rtn
  170.           LDA #>EXTGET
  171.           STA $BC
  172.           LDA CURLIN     ;Current line no. stored here
  173.           STA LINNOTMP   ;Store current line no. in
  174.           LDA CURLIN+1   ;
  175.           STA LINNOTMP+1 ;      temporary locations
  176.           LDA #$FF       ;Initialization of various flags
  177.           STA STEPFLG    ;Stepping mode active
  178.           STA PRTFLG     ;Current line no. to be printed
  179.           LDA #0
  180.           STA CONTFLG    ;No CONT state
  181.           STA NOWLNFLG   ;Line no. just executed not
  182.                          ;      to be printed
  183.           STA AUTOFLG    ;Not in autostep mode
  184.           LDX #<INSTALL
  185.           LDY #>INSTALL
  186.           STX AMPER+1    ;& vector pointed to
  187.                          ;      reinitialization of pgm
  188.           STY AMPER+2
  189.           STX TEMP
  190.           LDX #0
  191.           LDA #0
  192.           STA LISTTEMP   ;Clear line print flag
  193.           LDA #$FF
  194. CLLIN     STA LINSAV2,X
  195.           INX
  196.           CPX #7
  197.           BCC CLLIN      ;Clear saved line numbers
  198.           LDX TEMP
  199.           JSR CKPRODOS   ;ProDOS?
  200.           BEQ PRDS       ;Yes. Branch to PRDS
  201.           STX HIMEM      ;DOS 3.3. Set Himem
  202.           STY HIMEM+1
  203. PRDS      LDX #<KEYIN    ;Change input hook to go to KEYIN
  204.           LDY #>KEYIN    ;      rtn first
  205.           STX $38
  206.           STY $39
  207.           JSR CKPRODOS   ;ProDOS?
  208.           BEQ PRDS1      ;Yes. Branch to PRDS1
  209.           JSR $3EA       ;Tell DOS 3.3 of change to
  210.           RTS            ;      input hook
  211. PRDS1     STX $BE32      ;ProDOS current input vector
  212.           STY $BE33
  213.           JMP $BE00      ;Warm entry to ProDOS BI
  214. *
  215. **********************************************************
  216. *        MODIFIED KEYIN RTN                              *
  217. **********************************************************
  218. *
  219. KEYIN     PHA            ;Save (A) on stack
  220.           LDA PROMPT     ;Test prompt to see whether
  221.           CMP #$DD       ;      in immediate mode
  222.           BEQ KEYIN1     ;Immediate mode, branch to KEYIN1
  223.           PLA            ;Program execution mode,
  224.           BIT KBDSTRB    ;      restore (A) from stack and
  225.           JMP KYIN       ;      exit to Normal KEYIN rtn
  226. KEYIN1    PLA
  227.           JSR KYIN       ;Uses Normal KEYIN rtn for input
  228. *
  229. ************************ ;Rtn to resume execution of pgm
  230.                          ;      from immediate mode
  231.           CMP #$81       ;CTRL-A?
  232.           BNE KEYIN2
  233.           LDA #255       ;Yes, CTRL-A
  234.           STA STEPFLG    ;Activate stepping mode
  235.           STA PRTFLG     ;Activate print line no. mode
  236.           STA CONTFLG    ;Flag to indicate CONT is active
  237.           BIT KBDSTRB
  238. *
  239. CONT      LDX #0
  240. CONT1     LDA CONTM,X    ;Load CONT into input buffer to
  241.           STA $200,X     ;      be executed by Applesoft
  242.           INX
  243.           CPX #4
  244.           BNE CONT1
  245.           LDA #6         ;Store prompt to inform Applesoft
  246.           STA PROMPT     ;      pgm now in execution mode
  247.           LDA #$8D       ;Exit to Applesoft immediate mode
  248.           RTS            ;      to execute CONT and
  249.                          ;      resume pgm execution
  250. *
  251. ************************ ;Rtn to list out last six line
  252.                          ;      nos. just executed and
  253.                          ;      next line no. to be
  254.                          ;      executed
  255. KEYIN2    CMP #$84       ;CTRL-D?
  256.           BNE KEYIN3
  257.           LDA #0         ;Yes, CTRL-D
  258.           STA LISTTEMP   ;Deactivate listing of whole
  259.                          ;      lines
  260. LISTLN    LDY #6
  261. LISTLN1   CPY #1
  262.           BNE LISTLN2
  263.           LDA #$23
  264.           JSR COUT
  265. LISTLN2   JSR LINECUR    ;List last six lines just
  266.                          ;      executed and next line
  267.                          ;      to be executed
  268.           LDA LISTTEMP   ;Rest of line also listed?
  269.           BEQ LISTLN3
  270.           JSR CROUT      ;Yes. Output two carriage returns
  271.           JSR CROUT
  272. LISTLN3   LDY TEMPA      ;Restore (Y)
  273.           DEY
  274.           BPL LISTLN1    ;Some more lines to be printed
  275.           LDA #$8D       ;No more lines to be printed.
  276.           RTS            ;      Exit to immediate mode
  277. *
  278. ************************ ;Rtn to list last six lines just
  279.                          ;      executed and next line
  280.                          ;      to be executed
  281. KEYIN3    CMP #$9A       ;CTRL-Z?
  282.           BNE KEYIN4
  283.           JSR HOME       ;Yes, clear text screen
  284.           JSR TEXT       ;Switch to text screen
  285.           LDA #255
  286.           STA LISTTEMP   ;Activate listing of whole line
  287.           BNE LISTLN     ;Branch always
  288. *
  289. ************************ ;Rtn to list out all the simple
  290.                          ;      variables
  291. KEYIN4    CMP #$98       ;CTRL-X?
  292.           BEQ VAR
  293.           JMP KEYIN5
  294. VAR       JSR HOME       ;Yes, clear text screen
  295.           JSR TEXT       ;Switch to text screen
  296.           LDA VARTBL     ;Store pointer to variable table
  297.           STA VRYTBL     ;      in temporary locations
  298.           LDA VARTBL+1
  299.           STA VRYTBL+1
  300. VAR1      CMP VAREND+1   ;End of variable table (Hi-byte)?
  301.           BNE VAR2       ;No. Continue printing variables
  302.           LDA VRYTBL
  303.           CMP VAREND     ;End of variable table (Lo-byte)?
  304.           BNE VAR2       ;No. Continue printing variables
  305.           LDA #$8D       ;No more variables. Exit to
  306.           RTS            ;      Applesoft immediate mode
  307. *
  308. VAR2      JSR VARNTR     ;Format variable name to print
  309.           LDA NA         ;Print variable name
  310.           JSR OUTDO
  311.           LDA NA+1
  312.           JSR OUTDO
  313.           LDA (VRYTBL),Y
  314.           CMP #128       ;Determine type of variable
  315.           INY
  316.           BCC VAR3
  317.           LDA #$A5       ;Integer variable.
  318.           JSR PRINTEQL   ;Print "% ="
  319.           INY
  320.           INY
  321.           JSR PRNTINT    ;Print value of integer variable
  322.           BEQ VAR5       ;Branch always
  323. *
  324. VAR3      LDA (VRYTBL),Y
  325.           CMP #128       ;Determine type of variable
  326.           BCC VAR4
  327.           LDA #$A4       ;String variable
  328.           JSR PRINTEQL   ;Print "$ ="
  329.           LDA #$A2
  330.           JSR COUT       ;Print quote
  331.           LDA VRYTBL     ;Load string descriptor address
  332.           CLC
  333.           ADC #2         ;Point to correct address
  334.           STA FACMO
  335.           LDA VRYTBL+1
  336.           ADC #0
  337.           STA FACLO
  338.           JSR STRPRT     ;Print string pointed to by FAC
  339.           LDA #$A2
  340.           JSR COUT       ;Print quote
  341.           JMP VAR5
  342. *
  343. VAR4      LDA #$A0       ;Real variable
  344.           JSR PRINTEQL   ;Print "="
  345.           LDA VRYTBL     ;Load address of real variable
  346.           CLC
  347.           ADC #2         ;Point to correct address
  348.           PHA
  349.           LDA #0
  350.           ADC VRYTBL+1
  351.           TAY
  352.           PLA
  353.           JSR MOVFM      ;Move real variable pointed to by
  354.                          ;      (A) and (Y) into FAC
  355.           JSR PRNTFAC    ;Print value of real variable
  356. *
  357. VAR5      JSR PLACE      ;Align display of variables
  358. VAR6      LDA #7         ;Point variable pointer to
  359.           JSR INCVTBL    ;      next variable in table
  360.           LDA VRYTBL+1
  361.           JMP VAR1       ;Go back to print more variables
  362. *
  363. ************************ ;Rtn to list out all arrays
  364.                          ;
  365. KEYIN5    CMP #$96       ;CTRL-V?
  366.           BEQ ARY
  367.           JMP KEYIN6
  368. ARY       JSR HOME       ;Yes, clear text screen
  369.           JSR TEXT       ;Switch to text screen
  370.           LDA ARYTBL     ;Store pointer to array table in
  371.           STA VRYTBL     ;      temporary work locations
  372.           LDA ARYTBL+1
  373.           STA VRYTBL+1
  374. ARY1      CMP ARYEND+1   ;End of array table (Hi-byte)?
  375.           BNE ARY2       ;No. Continue printing arrays
  376.           LDA VRYTBL
  377.           CMP ARYEND     ;End of array table (Lo-byte)?
  378.           BNE ARY2       ;No. Continue printing arrays
  379.           LDA #$8D
  380.           RTS            ;No more arrays to be printed.
  381.                          ;      Exit to immediate mode
  382. *
  383. ARY2      LDY #4
  384.           LDA (VRYTBL),Y ;Load no. of dimensions of array
  385.           STA DIMTMP     ;      and store in DIMTMP
  386.           TAX            ;      and in (X)
  387. *
  388. ARY3      JSR VARNTR     ;Format array name for printing
  389.           LDA (VRYTBL),Y
  390.           CMP #128       ;Determine type of array
  391.           INY
  392.           BCC ARY5
  393. *
  394.           JSR SETBUF     ;Integer array. Set up BUFF
  395.                          ;      to print array subscripts
  396. ARY4      LDA #$A5       ;Load (A) with % sign
  397.           JSR PRINTNA    ;Print name, sign, and subscript
  398.           LDY #1
  399.           JSR PRNTINT    ;Print value of array element
  400.           LDA #2         ;Increment array pointer to point
  401.           JSR DIM        ;      to next element of array
  402.                          ;      and increment to next
  403.                          ;      subscript and see if last
  404.                          ;      element reached
  405.           BNE ARY4       ;Not last. Continue printing
  406.                          ;      integer array
  407. NXTARY    JSR CROUT      ;Yes, last. Output two carriage
  408.           JSR CROUT      ;      returns
  409.           LDA VRYTBL+1
  410.           BNE ARY1       ;Branch always to next array
  411. *
  412. ARY5      LDA (VRYTBL),Y
  413.           CMP #128       ;String array?
  414.           BCC ARY7
  415.           JSR SETBUF     ;Yes, set up BUFF for printing
  416.                          ;      array subscripts
  417. ARY6      LDA #$A4       ;Load (A) with $ sign
  418.           JSR PRINTNA    ;Print name, sign and subscript
  419.           LDA #$A2
  420.           JSR COUT       ;Print quote
  421.           LDA VRYTBL     ;Load string descriptor address
  422.           STA FACMO
  423.           LDA VRYTBL+1
  424.           STA FACLO
  425.           JSR STRPRT     ;Print string
  426.           LDA #$A2
  427.           JSR COUT       ;Print quote
  428.           LDA #3         ;Increment array pointer to point
  429.           JSR DIM        ;      to next element and
  430.                          ;      increment to next
  431.                          ;      subscript and see if last
  432.                          ;      element reached
  433.           BNE ARY6       ;Not last. Continue printing
  434.           BEQ NXTARY     ;Yes, last. Go on to next array
  435. *
  436. ARY7      JSR SETBUF     ;Real array. Set up input buffer
  437.                          ;      for printing subscripts
  438. ARY8      LDA #$A0       ;Load (A) with space
  439.           JSR PRINTNA    ;Print array name and subscript
  440.           LDA VRYTBL     ;Load (A) and (Y) with address of
  441.           LDY VRYTBL+1   ;      element of real array
  442.           JSR MOVFM      ;Move element of array pointed to
  443.                          ;      by (A) and (Y) into FAC
  444.           JSR PRNTFAC    ;Print value of element of array
  445.           LDA #5         ;Increment array pointer to point
  446.           JSR DIM        ;      to next element of array
  447.                          ;      and to increment to next
  448.                          ;      subscript and see if last
  449.                          ;      element reached
  450.           BNE ARY8       ;Not last. Continue printing
  451.           BEQ NXTARY     ;Yes, last. Go on to next array
  452. *
  453. ************************ ;Rtn for the setting and removing
  454.                          ;      of traps
  455. KEYIN6    CMP #$8C       ;CTRL-L?
  456.           BEQ TRAP       ;Yes, CTRL-L.
  457.           JMP KEYIN7
  458. TRAP      JSR TEXT       ;Switch to text screen
  459.           JSR DISTRAP    ;Display line nos. trapped
  460.           LDA #<TRAPTIT  ;Display Trap menu
  461.           LDY #>TRAPTIT
  462.           JSR STROUT
  463.           LDA #$60       ;Print a flashing blank
  464.           JSR COUT
  465.           DEC CH
  466. TRAP1     LDA KEYBOARD   ;Input choice from Trap menu
  467.           BPL TRAP1      ;No key pressed. Reread keyboard
  468.           BIT KBDSTRB    ;Key pressed. Strobe keyboard
  469.           CMP #$B1       ;Choice no. 1?
  470.           BNE TRAP2
  471.           LDX #2         ;Yes, check traps flag to see
  472. KEYTRP    LDA TFLG,X     ;      any traps not used
  473.           BNE KEYTRP1    ;Trap used. Next trap flag
  474.           STX TEMP       ;Trap unused. Save (X) register
  475.           LDA #<TRAPSET  ;Display TRAPS message
  476.           LDY #>TRAPSET
  477.           JSR STROUT
  478.           JSR GETLN      ;Input line no. to be trapped
  479.           CPX #0
  480.           BEQ KEYTRP2    ;Only <RETURN> key pressed. Exit to
  481.                          ;      Applesoft immediate mode
  482.           JSR GETNUM     ;Convert line no. and
  483.                          ;      store it in LINNUM
  484.           LDX TEMP       ;Restore (X) register to point to
  485.           LDA LINNUM     ;      current trap
  486.           STA TRP1,X     ;Save Lo-byte of trapped line no.
  487.           LDA LINNUM+1
  488.           STA TRP2,X     ;Save Hi-byte of trapped line no.
  489.           LDA #1
  490.           STA TFLG,X     ;Set trap flag to indicate that
  491.                          ;      current trap used
  492.           BNE KEYTRP2    ;Branch always to Applesoft
  493.                          ;      immediate mode
  494. KEYTRP1   DEX
  495.           BPL KEYTRP     ;Try next trap flag
  496.           LDA #<TRAPFUL  ;No free trap. Print
  497.           LDY #>TRAPFUL  ;      "TRAPS FULL" message
  498.           JSR STROUT
  499. KEYTRP2   LDX #0
  500.           LDA #$8D
  501.           RTS            ;Exit to Applesoft immediate mode
  502. TRAP2     CMP #$B2       ;Choice no. 2?
  503.           BNE TRAP3
  504.           LDA #<TRAPRMV  ;Yes. Display remove traps
  505.           LDY #>TRAPRMV  ;      message
  506.           JSR STROUT
  507.           JSR GETLN      ;Input line no. to be freed
  508.           CPX #0
  509.           BEQ KEYRMV2    ;Only <RETURN> key pressed. Exit to
  510.                          ;      Applesoft immediate mode
  511.           JSR GETNUM     ;Convert line no. and
  512.                          ;      store it in LINNUM
  513.           LDX #2
  514. KEYRMV    LDA TFLG,X     ;See if any traps used
  515.           BEQ KEYRMV1    ;Trap not used. Check next
  516.           LDA LINNUM     ;Trap used. See if Lo-byte of
  517.           CMP TRP1,X     ;      input line no. same as
  518.                          ;      trapped line no.
  519.           BNE KEYRMV1    ;Not same. Check next trap flag
  520.           LDA LINNUM+1   ;See if Hi-byte of input line
  521.           CMP TRP2,X     ;      no. same as trapped no.
  522.           BNE KEYRMV1    ;Not same. Check next trap flag
  523.           LDA #0
  524.           STA TFLG,X     ;Same. Reset trap flag to
  525.                          ;      indicate trap now freed
  526.           BEQ KEYRMV2    ;Branch always to Applesoft
  527.                          ;      immediate mode
  528. KEYRMV1   DEX            ;Try next trap flag to see if
  529.           BPL KEYRMV     ;      it is used
  530. KEYRMV2   LDX #0
  531.           LDA #$8D
  532.           RTS            ;Exit to Applesoft immediate mode
  533. *
  534. TRAP3     CMP #$B3       ;Choice no. 3?
  535.           BNE TRAP4
  536.           LDA #<RMVALL   ;Yes, display "ALL TRAPS
  537.           LDY #>RMVALL   ;      REMOVED" message
  538.           JSR STROUT
  539.           LDX #2
  540.           LDA #0         ;Zero out all the trap flags to
  541. DELTRP    STA TFLG,X     ;      indicate all traps free
  542.           DEX
  543.           BPL DELTRP
  544.           LDX #0
  545.           LDA #$8D
  546.           RTS            ;Exit to Applesoft immediate mode
  547. *
  548. TRAP4     CMP #$8D       ;Return key?
  549.           BEQ TRAPRET    ;Yes. Exit trap menu
  550.           JMP TRAP1      ;No. Go back to reread keyboard
  551. TRAPRET   RTS            ;Exit to Applesoft immediate mode
  552. *
  553. ************************ ;Rtn to switch to text screen
  554. KEYIN7    CMP #$86       ;CTRL-F?
  555.           BNE KEYIN8
  556.           JSR TEXT       ;Yes, switch to text screen
  557.           LDA #$8D
  558.           RTS            ;Exit to immediate mode
  559. *
  560. ************************ ;Rtn to switch to Hires page 1
  561. KEYIN8    CMP #$92       ;CTRL-R?
  562.           BNE KEYIN9
  563.           JSR HIRES1     ;Yes, switch to Hires page 1
  564.           LDA #$8D
  565.           RTS            ;Exit to immediate mode
  566. *
  567. ************************ ;Rtn to switch to Lores page 1
  568. KEYIN9    CMP #$87       ;CTRL-G?
  569.           BNE KEYIN10
  570.           JSR LORES      ;Yes, switch to Lores page 1
  571.           LDA #$8D
  572.           RTS            ;Exit to immediate mode
  573. *
  574. ************************ ;Rtn to switch to Hires page 2
  575. KEYIN10   CMP #$94       ;CTRL-T?
  576.           BNE KEYIN11
  577.           JSR HIRES2     ;Yes, Switch to Hires page 2
  578.           LDA #$8D
  579.           RTS            ;Exit to immediate mode
  580. *
  581. ************************ ;Rtn to restore normal Applesoft
  582.                          ;      Chrget code
  583. KEYIN11   CMP #$8F       ;CTRL-O?
  584.           BNE KEYRET
  585.           LDA #$C9       ;Yes, restore Chrget rtn to its
  586.           STA $BA        ;      original code
  587.           LDA #$3A
  588.           STA $BB
  589.           LDA #$B0
  590.           STA $BC
  591.           LDX #<KYIN     ;Restore normal KEYIN Hook
  592.           LDY #>KYIN
  593.           STX $38
  594.           STY $39
  595.           JSR CKPRODOS   ;ProDOS?
  596.           BEQ KEYRET1    ;Yes. Branch to KEYRET1
  597.           JSR $3EA       ;Tell DOS 3.3 of change in
  598.                          ;      KEYIN Hook
  599. KEYRET2   LDX #0
  600.           LDA #$8D       ;Issue carriage return
  601. KEYRET    RTS            ;Exit to Applesoft immediate mode
  602. KEYRET1   STX $BE32      ;ProDOS current input vector
  603.           STY $BE33
  604.           BEQ KEYRET2    ;Branch always
  605. *
  606. *
  607. *
  608. **********************************************************
  609. *        MODIFIED CHRGET RTN                             *
  610. **********************************************************
  611. *
  612. EXTGET    STA AHOLD      ;Save (A)
  613.           STX XREG       ;Save (X)
  614.           STY YREG       ;Save (Y)
  615.           PHP            ;Push status register (P) onto
  616.           PLA            ;      stack before saving (P)
  617.           STA STATUS     ;      into STATUS location
  618. *
  619.           LDA $B9        ;Applesoft in immediate or
  620.           CMP #$8        ;      program execution mode?
  621.           BCS EXTGET1    ;Applesoft in pgm execution mode,
  622.                          ;      continue with EXTGET1 rtn
  623.           JMP IGNOR      ;Applesoft in immediate mode,
  624.                          ;      exit to CHRGET at IGNOR
  625. *
  626. EXTGET1   LDA CONTFLG    ;Program just resumed execution?
  627.           BEQ EXTGET2
  628.           LDX #0         ;Yes. Deactivate CONTFLG
  629.           STX CONTFLG
  630. RESTSCN   LDA SVTXT1,X   ;Restore text screen to state
  631.           STA 1024,X     ;      just before break in
  632.           LDA SVTXT2,X   ;      program execution
  633.           STA 1280,X
  634.           LDA SVTXT3,X
  635.           STA 1536,X
  636.           LDA SVTXT4,X
  637.           STA 1792,X
  638.           DEX
  639.           BNE RESTSCN
  640.           LDX #3         ;Restore text window to state
  641. WNDA      LDA WNDTMPRY,X ;      just before break in
  642.           STA WNDS,X     ;      program execution
  643.           DEX
  644.           BPL WNDA
  645.           LDA CHTEMP     ;Restore cursor to location just
  646.           STA CH         ;      before break in program
  647.           LDA CVTEMP     ;      execution
  648.           JSR TABV
  649.           JMP PRNLN      ;Jump to print the program line
  650. *
  651. EXTGET2   LDA KEYBOARD   ;Read keyboard
  652.           CMP #$81       ;CTRL-A?
  653.           BNE EXTGET5
  654.           LDA AUTOFLG    ;Yes. Is auto line printing
  655.                          ;      mode active?
  656.           BNE EXTGET5    ;Yes. Program not allowed to halt
  657.           LDA CURLIN     ;No, not active. Check Lo-byte of
  658.           CMP LINNOTMP   ;      CURLIN to see if Applesoft
  659.                          ;      still executing same line
  660.           BNE EXTGET3    ;No, Applesoft executing a new
  661.                          ;      line. Pgm allowed to halt
  662.           LDA CURLIN+1   ;Applesoft still executing the
  663.           CMP LINNOTMP+1 ;      same line?
  664.           BNE EXTGET3    ;No. Program allowed to halt
  665.           JMP IGNOR      ;Yes. Exit to CHRGET at IGNOR
  666. EXTGET3   JSR SAVLIN     ;Save last six executed line nos.
  667.                          ;      and current line no.
  668.                          ;      to be executed
  669. EXTGET4   BIT KBDSTRB    ;Clear keyboard strobe
  670.           LDA CH
  671.           STA CHTEMP     ;Save horizontal cursor position
  672.           LDA CV
  673.           STA CVTEMP     ;Save vertical cursor position
  674.           LDX #3
  675. WNDB      LDA WNDS,X     ;Save current state of text
  676.           STA WNDTMPRY,X ;      window into temporary
  677.           DEX            ;      locations
  678.           BPL WNDB
  679. *
  680.           LDX #0         ;Save text screen in temporary
  681. SVSCN     LDA 1024,X     ;      area following user
  682.           STA SVTXT1,X   ;      requested break in program
  683.           LDA 1280,X     ;      execution
  684.           STA SVTXT2,X
  685.           LDA 1536,X
  686.           STA SVTXT3,X
  687.           LDA 1792,X
  688.           STA SVTXT4,X
  689.           DEX
  690.           BNE SVSCN
  691. *
  692.           LDA CURLIN     ;Store line no. at which program
  693.           STA OLDLIN     ;      execution halted in OLDLIN
  694.           LDA CURLIN+1
  695.           STA OLDLIN+1
  696.           JSR SETTXT1    ;Restore text screen to normal
  697.                          ;      values and place cursor
  698.                          ;      at bottom of screen
  699.           JSR CROUT
  700.           LDX $F8        ;Stop execution of program when
  701.           TXS            ;      CTRL-A pressed and exit to
  702.           JMP PGMSTP     ;      Applesoft immediate mode
  703. *
  704. EXTGET5   CMP #$97       ;CTRL-W?
  705.           BNE EXTGET6
  706.           LDA #255       ;Yes. Activate following flags
  707.           STA STEPFLG    ;Stepping mode active
  708.           STA PRTFLG     ;Line no. print active
  709.           LDA #0
  710.           STA AUTOFLG    ;No Auto line stepping mode
  711. *
  712. EXTGET6   LDA CURLIN     ;Applesoft still executing the
  713.           CMP LINNOTMP   ;      same line?
  714.           BNE EXTGET7
  715.           LDA CURLIN+1
  716.           CMP LINNOTMP+1
  717.           BNE EXTGET7
  718.           JMP IGNOR      ;Yes. Exit to CHRGET at IGNOR
  719. *
  720. EXTGET7   JSR SAVLIN     ;No. Save last six executed line
  721.                          ;      nos. and current line no.
  722.                          ;      to be executed
  723.           LDX #2
  724. TRAPS     LDA TFLG,X     ;Check current line no. to see
  725.           BEQ TRAPS1     ;      if it has been trapped
  726.           LDA TRP1,X
  727.           CMP CURLIN
  728.           BNE TRAPS1
  729.           LDA CURLIN+1
  730.           CMP TRP2,X
  731.           BNE TRAPS1
  732.           JSR BELL       ;Line no. trapped, sound bell
  733.           LDX #255       ;      and activate stepping mode
  734.           STX STEPFLG
  735.           INX
  736.           STX AUTOFLG
  737.           BNE EXTGET8    ;      and branch to EXTGET8
  738. TRAPS1    DEX
  739.           BPL TRAPS
  740. *
  741. EXTGET8   LDA STEPFLG    ;Stepping mode active?
  742.           BNE PRNLN
  743.           JMP IGNOR      ;No, Exit to CHRGET at IGNOR
  744. *
  745. PRNLN     LDA INVFLG     ;Yes. Save current screen output
  746.           STA VIDEOTMP   ;      mode (normal, inverse or
  747.                          ;      flashing)
  748.           LDA CH
  749.           STA CHTEMP     ;Save horizontal cursor position
  750.           LDA CV
  751.           STA CVTEMP     ;Save vertical cursor position
  752. *
  753. STORE     LDX #39        ;Save last four lines of text
  754. STORE1    LDA $650,X     ;      screen into temporary
  755.           STA SVTX1,X    ;      locations
  756.           LDA $6D0,X
  757.           STA SVTX2,X
  758.           LDA $750,X
  759.           STA SVTX3,X
  760.           LDA $7D0,X
  761.           STA SVTX4,X
  762.           DEX
  763.           BPL STORE1
  764. *
  765. MODE      LDA PRTFLG     ;Print line no. flag active?
  766.           BEQ WAITKEY    ;No. Skip printing of line
  767. *
  768. PRBLK     LDA #$20       ;Yes. Blank out last four lines
  769.           LDX #39        ;      of text screen with
  770. PRBLK1    STA $650,X     ;      inverse spaces
  771.           STA $6D0,X
  772.           STA $750,X
  773.           STA $7D0,X
  774.           DEX
  775.           BPL PRBLK1
  776. *
  777.           LDA #$3F       ;Line to be printed in inverse
  778.           STA INVFLG
  779.           LDA WNDTOP     ;Save current top line of
  780.           STA WNDTMP     ;      text window
  781.           LDA #0         ;Place cursor at beginning of
  782.           STA CH         ;      line
  783.           LDA #20        ;Set current top line of text
  784.           STA WNDTOP     ;      window to line 21
  785.           JSR TABV
  786. *
  787.           LDA #$F0       ;Disconnect DOS hook. Restore
  788.           STA $36        ;      character output switch
  789.           LDA #$FD       ;      (CSW) to point to COUT1.
  790.           STA $37        ;      This is to enable program
  791.                          ;      to step through DOS
  792. *
  793.           LDA NOWLNFLG   ;Current line or line which has
  794.                          ;      just executed to be
  795.                          ;      printed?
  796.           BEQ PRNXT      ;Current line to be executed to
  797.                          ;      be printed.
  798.                          ;      Branch to PRNXT
  799.           JSR NOWLIN     ;Line which has just executed to
  800.                          ;      be printed. Call NOWLIN
  801.           BEQ AUTOSTP    ;Branch always to AUTOSTP
  802. *
  803. PRNXT     JSR LINPRT     ;Print line no. of current line
  804.           LDA #$A0       ;Print space between line no.
  805.           JSR COUT       ;      and line statement
  806.           JSR PRNTLN     ;Print rest of current line
  807.                          ;      to be executed
  808. *
  809. AUTOSTP   LDX $9D04      ;Reconnect DOS hook into CSW
  810.           LDY $9D05
  811.           JSR CKPRODOS   ;ProDOS?
  812.           BNE AUTOSTPZ   ;No
  813.           LDX $BE34      ;Yes. BI's output intercept
  814.           LDY $BE35      ;      address
  815. AUTOSTPZ  STX $36        ;DOS hook reconnected into CSW
  816.           STY $37
  817. AUTOSTP0  LDA WNDTMP     ;Restore current top line of
  818.           STA WNDTOP     ;      text window
  819.           LDA AUTOFLG    ;Auto-stepping mode active?
  820.           BEQ WAITKEY
  821.           LDA CONTSPED   ;Yes. Speed of auto-stepping mode
  822.                          ;      zero (fastest) ?
  823.           BEQ WAITKEY2   ;Yes. Do not wait
  824. AUTOSTP1  TAX            ;No. Wait
  825. AUTOSTP2  JSR $FCA8      ;Call waiting subroutine
  826.           LDY KEYBOARD   ;Read keyboard
  827.           CPY #$97       ;CTRL-W ?
  828.           BEQ AUTOSTP3   ;Yes. Exit waiting loop
  829.           DEX            ;No. Continue waiting until
  830.           BNE AUTOSTP2   ;      (X) decreases to zero
  831. AUTOSTP3  JMP REST       ;Exit waiting loop
  832. *
  833. WAITKEY   BIT KBDSTRB    ;Clear keyboard strobe
  834. WAITKEY1  LDA KEYBOARD   ;Read keyboard
  835.           BPL WAITKEY1   ;No key pressed. Reread keyboard
  836.           CMP #$85       ;CTRL-E?
  837.           BNE GET1
  838.           LDA #0         ;Yes. Deactivate stepping mode
  839.           STA STEPFLG
  840. WAITKEY2  JMP REST       ;      and jump to REST
  841. *
  842. *
  843. GET1      CMP #$9B       ;ESC?
  844.           BNE GET2
  845.           LDA PRTFLG     ;Yes. Activate or deactivate
  846.                          ;      line printing mode?
  847.           BNE ESC        ;Line printing mode active.
  848.                          ;      Branch to ESC
  849.           LDA #$FF       ;Line printing mode not active.
  850.           STA PRTFLG     ;      Activate it and jump back
  851.           JMP PRBLK      ;      to print line
  852. ESC       JSR RESTORE    ;Restore last four lines of
  853.                          ;      screen to normal
  854.           LDA #0
  855.           STA PRTFLG     ;Deactivate line printing mode
  856.           BEQ WAITKEY    ;Branch always to reread keyboard
  857. *
  858. GET2      CMP #$91       ;CTRL-Q?
  859.           BNE GET3
  860.           LDA NOWLNFLG   ;Yes. Toggle between printing of
  861.                          ;      line which has just
  862.           BNE CTRLQ      ;      executed and line to be
  863.           LDA #255       ;      executed
  864.           BNE CTRLQ1
  865. CTRLQ     LDA #0
  866. CTRLQ1    STA NOWLNFLG
  867.           JMP MODE       ;Jump back to MODE where line
  868.                          ;      will be printed if
  869.                          ;      PRTFLG active
  870. *
  871. GET3      CMP #$86       ;CTRL-F?
  872.           BNE GET4
  873.           JSR TEXT       ;Yes. Switch to text screen
  874.           BCS WAITKEY    ;Branch always to reread keyboard
  875. GET4      CMP #$92       ;CTRL-R?
  876.           BNE GET5
  877.           JSR HIRES1     ;Yes. Switch to Hires page 1
  878.           BCS WAITKEY    ;Branch always to reread keyboard
  879. GET5      CMP #$94       ;CTRL-T?
  880.           BNE GET6
  881.           JSR HIRES2     ;Yes. Switch to Hires page 2
  882.           BCS WAITKEY    ;Branch always to reread keyboard
  883. GET6      CMP #$87       ;CTRL-G?
  884.           BNE GET7
  885.           JSR LORES      ;Yes. Switch to Lores page 1
  886.           BCS WAITKEY    ;Branch always to reread keyboard
  887. *
  888. GET7      CMP #$81       ;CTRL-A?
  889.           BNE GET8
  890.           JSR RESTR      ;Yes. restore the last four lines
  891.                          ;      of text screen, horizontal
  892.                          ;      and vertical cursor
  893.                          ;      position and INVFLG
  894.           JMP EXTGET4    ;Jump back to halt pgm execution
  895. *
  896. GET8      CMP #$84       ;CTRL-D?
  897.           BNE REST
  898.           BIT KBDSTRB    ;Yes. Clear keyboard strobe
  899. ATOSTEP   LDA KEYBOARD   ;Read keyboard
  900.           BPL ATOSTEP    ;No key pressed. Reread keyboard
  901.           BIT KBDSTRB    ;Key pressed. Strobe keyboard
  902.           CMP #$B0       ;Less than '0'?
  903.           BCC ATOSTEP2   ;Yes. Branch to ATOSTEP2
  904.           CMP #$BA       ;No. Greater than '9'?
  905.           BCS ATOSTEP2   ;Yes. Branch to ATOSTEP2
  906.           AND #$0F       ;No. Convert to binary
  907.           ASL            ;Double the binary number
  908.           CMP #18        ;Binary number 18?
  909.           BNE ATOSTEP1   ;No. Branch to ATOSTEP1
  910.           LDA #50        ;Yes. Change it to 50
  911. ATOSTEP1  STA CONTSPED   ;Store binary number in CONTSPED
  912. ATOSTEP2  LDA #255
  913.           STA AUTOFLG    ;Activate auto-stepping mode
  914. *
  915. *
  916. REST      JSR RESTR      ;Restore last four lines of Text
  917.                          ;      screen, horizontal and
  918.                          ;      vertical cursor position
  919.                          ;      and state of INVFLG
  920. *
  921. IGNOR     LDA STATUS
  922.           PHA
  923.           LDX XREG       ;Restore (X)
  924.           LDY YREG       ;Restore (Y)
  925.           PLP            ;Restore status register (P)
  926. *
  927.           LDA AHOLD      ;Restore (A)
  928.           CMP #':
  929.           BCS IGNOR1
  930.           JMP $BE
  931. IGNOR1    RTS            ;Exit to CHRGET
  932. *
  933. *
  934. *
  935. **********************************************************
  936. *        VARIOUS SUBROUTINES                             *
  937. **********************************************************
  938. *
  939. ************************ ;Rtn to restore the last four
  940.                          ;      lines of text screen,
  941.                          ;      horizontal and vertical
  942.                          ;      cursor position and INVFLG
  943. RESTR     JSR RESTORE    ;Restore last four lines of text
  944.                          ;      screen to normal
  945.           LDA CHTEMP     ;Restore horizontal cursor
  946.           STA CH         ;      position
  947.           LDA CVTEMP
  948.           JSR TABV       ;Restore vertical cursor position
  949.           LDA VIDEOTMP
  950.           STA INVFLG     ;Restore INVFLG to original state
  951.           RTS
  952. *
  953. ************************ ;Rtn to restore the last four
  954.                          ;      lines of text screen
  955. RESTORE   LDX #39
  956. RESTORE1  LDA SVTX1,X
  957.           STA $650,X
  958.           LDA SVTX2,X
  959.           STA $6D0,X
  960.           LDA SVTX3,X
  961.           STA $750,X
  962.           LDA SVTX4,X
  963.           STA $7D0,X
  964.           DEX
  965.           BPL RESTORE1
  966.           RTS
  967. *
  968. ************************ ;Rtn to save last six executed
  969.                          ;      line nos. and current line
  970.                          ;      no. to be executed
  971. SAVLIN    LDX #5
  972. SAVLIN1   LDA LINSAV1,X  ;Each time a new line is
  973.           LDY LINSAV2,X  ;      executed, the last six
  974.           INX            ;      line nos. are shifted
  975.           STA LINSAV1,X  ;      successively up and the
  976.           TYA
  977.           STA LINSAV2,X
  978.           DEX
  979.           DEX
  980.           BPL SAVLIN1
  981.           INX
  982.           LDA CURLIN     ;      current line no. is saved
  983.           STA LINSAV1,X  ;      at the bottom of the
  984.           STA LINNOTMP   ;      reserved storage locations
  985.           LDA CURLIN+1   ;      and in LINNOTMP
  986.           STA LINSAV2,X
  987.           STA LINNOTMP+1
  988.           RTS
  989. *
  990. ************************ ;Rtn to print line just executed
  991. NOWLIN    LDA #255
  992.           STA LISTTEMP   ;Activate flag to indicate whole
  993.                          ;      line to be printed
  994.           LDA #$A3       ;Print "#" sign before printing
  995.           JSR COUT       ;      rest of line
  996.           LDY #1         ;Go on to LINECUR rtn
  997. *
  998. ************************ ;Rtn to print out whole line
  999.                          ;      or only the line no.
  1000.                          ;      depending on state of
  1001.                          ;      LISTTEMP flag
  1002. LINECUR   LDX LINSAV1,Y  ;Load (X) and (A) with line no.
  1003.           STX LINNUM
  1004.           LDA LINSAV2,Y  ;      and also save it in LINNUM
  1005.           CMP #$FF       ;empty, don't print it
  1006.           BEQ LINECUR2
  1007.           STA LINNUM+1   ;      to be used by FINDLIN to
  1008.                          ;      locate line
  1009.           STY TEMPA      ;Save the (Y) register
  1010. LLCUR     JSR LINPRNT    ;Print out line no.
  1011.           LDA #$A0
  1012.           JSR COUT       ;Print a blank space
  1013.           LDA LISTTEMP   ;Rest of line to be printed?
  1014.           BEQ LINECUR1
  1015.           JSR PRNTLN1    ;Yes. Print out rest of line
  1016. LINECUR1  RTS
  1017. LINECUR2  LDX #0
  1018.           LDA #$8D
  1019.           STA BUFF       ;clear input buffer
  1020.           TXA            ;put zero in A
  1021.           STY TEMPA      ;save Y
  1022.           RTS
  1023. *
  1024. ************************ ;Rtn to print out rest of line
  1025. PRNTLN    LDA CURLIN
  1026.           STA LINNUM
  1027.           LDA CURLIN+1
  1028.           STA LINNUM+1
  1029. PRNTLN1   JSR FINDLIN    ;Get starting address of line
  1030.           LDY #4
  1031. PRNTLN2   LDA (LOWTR),Y  ;End of line reached?
  1032.           BEQ PRNTLN3    ;Yes. Return to calling rtn
  1033.           BMI EVTOKEN    ;No. Hi-bit set.
  1034.                          ;      Branch to EVTOKEN
  1035.           JSR OUTDO      ;Hi-bit not set. Print character
  1036.           INY            ;Point to next byte of current
  1037.                          ;      line
  1038.           BNE PRNTLN2    ;Branch always
  1039. PRNTLN3   RTS
  1040. *
  1041. EVTOKEN   SEC            ;Modified Applesoft list rtn
  1042.           SBC #$7F
  1043.           TAX
  1044.           STY $85
  1045.           LDY #$D0
  1046.           STY $9D
  1047.           LDY #$CF
  1048.           STY $9E
  1049.           LDY #$FF
  1050. INCPNTR   DEX
  1051.           BEQ TKNFND
  1052. INCPNTR1  JSR INCPTR
  1053.           BPL INCPNTR1
  1054.           BMI INCPNTR
  1055. TKNFND    LDA #$A0       ;Print space followed by
  1056.           JSR COUT
  1057. TKNPRNT   JSR INCPTR
  1058.           BMI TKNPRNT1
  1059.           JSR OUTDO      ;      Applesoft token word
  1060.           BNE TKNPRNT
  1061. TKNPRNT1  JSR OUTDO
  1062.           LDA #$A0
  1063.           JSR COUT
  1064.           LDY $85
  1065.           INY
  1066.           BNE PRNTLN2    ;Branch always
  1067. *
  1068. ************************ ;Rtn to display the Trap menu and
  1069.                          ;      display the line nos.
  1070.                          ;      which have been trapped
  1071. DISTRAP   LDA #<TRAPDISP ;Display the Trap menu when
  1072.           LDY #>TRAPDISP ;      CTRL-K pressed
  1073.           JSR STROUT
  1074.           LDY #2
  1075. DISTRAP1  LDA TFLG,Y     ;Display line nos. which have
  1076.           BEQ DISTRAP2
  1077.           LDA TRP2,Y     ;      been trapped
  1078.           LDX TRP1,Y
  1079.           STY TEMP
  1080.           JSR LINPRNT
  1081.           LDA #$A0       ;Print a blank space
  1082.           JSR COUT
  1083.           LDY TEMP
  1084. DISTRAP2  DEY
  1085.           BPL DISTRAP1
  1086.           RTS
  1087. *
  1088. ************************ ;Rtn to convert input line no.
  1089.                          ;      and place it in LINNUM
  1090. GETNUM    JSR GDBUFS     ;Put zero at end of input buffer
  1091.                          ;      and mask off most
  1092.                          ;      significant bit on
  1093.                          ;      all bytes
  1094.           LDA #0         ;Re-point TXTPTR to start of
  1095.           STA TXTPTR     ;      input buffer
  1096.           LDA #2
  1097.           STA TXTPTR+1
  1098.           JSR FRMNUM     ;Evaluate line no. stored in
  1099.                          ;      input buffer and put the
  1100.                          ;      result in FAC
  1101.           JSR GETADR     ;Convert FAC to two-byte integer
  1102.                          ;      and store it in LINNUM
  1103.           RTS
  1104. *
  1105. ************************ ;Rtn to increase variable or
  1106.                          ;      array pointer to point to
  1107.                          ;      start of variable or array
  1108. INCVTBL   CLC
  1109.           ADC VRYTBL
  1110.           STA VRYTBL
  1111.           BCC INCVTBL1
  1112.           INC VRYTBL+1
  1113. INCVTBL1  RTS
  1114. *
  1115. ************************ ;Rtn to print " = " during
  1116.                          ;      listing of variables
  1117.                          ;      and arrays
  1118. PRINTEQL  JSR COUT
  1119.           LDA #$A0
  1120.           JSR COUT       ;Print a space
  1121.           LDA #$BD
  1122.           JSR COUT       ;Print the "=" sign
  1123.           LDA #$A0
  1124.           JSR COUT       ;Print a space
  1125.           RTS
  1126. *
  1127. ************************ ;Rtn to format the variable and
  1128.                          ;      array name for printing
  1129.                          ;      to screen
  1130. VARNTR    LDY #1
  1131.           LDA (VRYTBL),Y ;Name single or double lettered?
  1132.           AND #$7F       ;Zero out the hi-bit
  1133.           BNE VARBL      ;Double-lettered name
  1134.           LDA #$A0       ;Single-lettered name. Second
  1135.                          ;      letter filled with space
  1136. VARBL     STA NA+1       ;Store variable or array name in
  1137.           DEY            ;      NA before printing it out
  1138.           LDA (VRYTBL),Y
  1139.           STA NA
  1140.           RTS
  1141. *
  1142. ************************ ;Rtn to print  value of integer
  1143.                          ;      variable or array
  1144. PRNTINT   LDA (VRYTBL),Y
  1145.           TAX            ;Load (X) with hi-byte of integer
  1146.           DEY
  1147.           LDA (VRYTBL),Y ;Load (A) with lo-byte of integer
  1148.           JSR LINPRNT    ;Print value of the integer
  1149.           RTS
  1150. *
  1151. ************************ ;Rtn to align the listing of the
  1152.                          ;      variables and arrays into
  1153.                          ;      two columns
  1154. PLACE     LDA #20
  1155.           CMP CH
  1156.           STA CH
  1157.           BCS PLACE1
  1158.           JSR CROUT      ;Length of previous variable or
  1159.                          ;      array element too long.
  1160.                          ;      Position current variable
  1161.                          ;      or array element to be
  1162.                          ;      printed on a new line
  1163. PLACE1    RTS
  1164. *
  1165. ************************ ;Rtn to set up buffer for the
  1166.                          ;      printing of array
  1167.                          ;      subscripts
  1168. SETBUF    LDA #5         ;Increment array pointer to point
  1169.           JSR INCVTBL    ;      to the table of array
  1170.                          ;      dimensions
  1171.           LDA VRYTBL     ;Store address of the table
  1172.           STA PTR        ;      of array dimensions
  1173.           LDA VRYTBL+1   ;      in PTR
  1174.           STA PTR+1
  1175. *
  1176.           LDY #0
  1177. SETBUF1   LDA #0         ;Initialize to zero the bottom
  1178.           STA BUFF,Y     ;      part of BUFF to be used in
  1179.           INY            ;      printing array subscripts
  1180.           STA BUFF,Y
  1181.           INY
  1182.           LDA #2         ;Increment array pointer to point
  1183.           JSR INCVTBL    ;      to actual start of array
  1184.           DEX
  1185.           BNE SETBUF1
  1186.           RTS
  1187. *
  1188. ************************ ;Rtn to print out the name and
  1189.                          ;      subscript of array element
  1190. PRINTNA   STA NA+2       ;Store sign for the type of array
  1191.           LDY #>NA
  1192.           LDA #<NA       ;Print name of array element
  1193.           JSR STROUT     ;      followed by "("
  1194. *
  1195.           LDA DIMTMP     ;Load (A) with no. of dimensions
  1196.           ASL            ;      of array and times by two
  1197.           TAY            ;      and store it in (Y) to be
  1198.                          ;      used as counter
  1199. PRINTNA1  DEY
  1200.           LDA BUFF,Y     ;Load (X) and (A) with particular
  1201.           TAX            ;      subscript of current
  1202.                          ;      element of array
  1203.           DEY
  1204.           STY TEMP
  1205.           LDA BUFF,Y
  1206.           JSR LINPRNT    ;Print subscript of array element
  1207.           LDY TEMP
  1208.           BEQ PRINTNA2   ;Branch if no more subscripts of
  1209.                          ;      current array element to
  1210.                          ;      be printed
  1211.           LDA #","       ;Print comma within subscript of
  1212.           JSR COUT       ;      multidimensional array
  1213.           BNE PRINTNA1   ;Branch always to print rest of
  1214.                          ;      array subscript
  1215. PRINTNA2  LDA #")"
  1216.           JSR PRINTEQL   ;Print ") = "
  1217.           RTS
  1218. *
  1219. ************************ ;Rtn to align printing of array
  1220.                          ;      and see if last element of
  1221.                          ;      array printed
  1222. DIM       JSR INCVTBL    ;Increment array pointer to point
  1223.                          ;      to next element of array
  1224.           JSR PLACE      ;Align printing of array
  1225. *
  1226.           LDA DIMTMP     ;Load (A) with no. of dimensions
  1227.           ASL            ;      of array ,multiply by two
  1228.           TAY            ;      and store it in (Y) to be
  1229.                          ;      used as counter
  1230. DIM1      DEY
  1231.           LDA BUFF,Y     ;Store the size of subscript plus
  1232.           STA TMP+1      ;      one in TMP and TMP+1 to be
  1233.           DEY            ;      used for comparison in
  1234.           LDA BUFF,Y     ;      incrementing subscript
  1235.           STA TMP
  1236.           INC TMP+1
  1237.           BNE DIM2
  1238.           INC TMP
  1239. DIM2      LDA TMP        ;Compare current subscript to see
  1240.           CMP (PTR),Y    ;      if it has reached its
  1241.           BNE DIM3       ;      dimensioned size. If not
  1242.           INY            ;      then branch to increment
  1243.           LDA TMP+1      ;      subscript
  1244.           CMP (PTR),Y
  1245.           BNE DIM4
  1246. *
  1247.           LDA #0         ;Reset to zero any particular
  1248.           STA BUFF,Y     ;      subscript which has
  1249.           DEY            ;      execeeded its dimensioned
  1250.           STA BUFF,Y     ;      size
  1251.           BNE DIM1
  1252.           RTS
  1253. *
  1254. DIM3      INY            ;Increment subscript stored in
  1255. DIM4      TYA            ;      BUFF
  1256.           TAX
  1257.           INC BUFF,X
  1258.           BNE DIM5
  1259.           DEX
  1260.           INC BUFF,X
  1261. DIM5      RTS
  1262. *
  1263. ************************ ;Rtn to switch to text screen
  1264. TEXT      BIT $C054
  1265.           BIT $C051
  1266.           RTS
  1267. *
  1268. ************************ ;Rtn to switch to Lores page 1
  1269. LORES     BIT $C054
  1270.           BIT $C056
  1271.           BIT $C050
  1272.           RTS
  1273. *
  1274. ************************ ;Rtn to switch to Hires page 1
  1275. HIRES1    BIT $C054
  1276.           BIT $C050
  1277.           BIT $C057
  1278.           RTS
  1279. *
  1280. ************************ ;Rtn to switch to Hires page 2
  1281. HIRES2    BIT $C050
  1282.           BIT $C057
  1283.           BIT $C055
  1284.           RTS
  1285. *
  1286. ************************ ;Rtn to check whether ProDOS is
  1287.                          ;      active
  1288. CKPRODOS  LDA $BF00      ;For ProDOS, location $BF00
  1289.           CMP #$4C       ;      contains the value $4C
  1290.           RTS
  1291. *
  1292. *
  1293. **********************************************************
  1294. * VARIOUS MESSAGES AND RESERVED LOCATIONS USED BY PROGRAM*
  1295. **********************************************************
  1296. CONTM     ASC "CONT"
  1297. *
  1298. TRAPDISP  ASC "TRAPS: "
  1299.           HEX 00
  1300. TRAPSET   ASC " SET? "
  1301.           HEX 00
  1302. TRAPRMV   ASC " REMOVE? "
  1303.           HEX 00
  1304. TRAPFUL   ASC " TRAPS FULL"
  1305.           HEX 00
  1306. RMVALL    ASC " ALL TRAPS REMOVED"
  1307.           HEX 00
  1308. TRAPTIT   HEX 0D,0D
  1309.           ASC "1. SET TRAP           2. REMOVE A TRAP  "
  1310.           ASC "3. REMOVE ALL TRAPS    OR PRESS RETURN  "
  1311.           HEX 0D,00
  1312. *
  1313. WNDTMPRY  DFB 0,40,0,24
  1314. *
  1315. CONTSPED  DFB 8
  1316. *
  1317. LINSAV1   HEX 00,00,00,00,00,00,00
  1318. LINSAV2   HEX 00,00,00,00,00,00,00
  1319. *
  1320. TRP1      HEX 00,00,00
  1321. TRP2      HEX 00,00,00
  1322. TFLG      HEX 00,00,00
  1323. *
  1324. NA        HEX 00,00,00
  1325.           DFB $A8,0
  1326. *
  1327. TMP       DS 2
  1328. DIMTMP    DS 1
  1329. *
  1330. SVTXT1    = *
  1331. SVTX1     DS 40
  1332. SVTX2     DS 40
  1333. SVTX3     DS 40
  1334. SVTX4     DS 40
  1335.           DS 96
  1336. SVTXT2    DS 256
  1337. SVTXT3    DS 256
  1338. SVTXT4    DS 256
  1339. *
  1340. *
  1341. END1      = *
  1342. END       = START+END1-INSTALL
  1343.